
.def rom_start $0000
.def ram_start $8000
.def stack_size $0100

.def if_equal(val, action) pha, cmp val, jnz {, action, }, ppa,
.def inc_carry(r1, r2) in%r2, jnc {, in%r1, },
.def inxy inc_carry(x, y)
.def phxy phx, phy
.def ppxy ppy, ppx

.org rom_start ; start of ROM

lxy #main_program, xxi ; setup program entry point
lxy #stack_page, xxs   ; setup stack
run                    ; allow program to run upon interrupt exit
{                      ; interrupt routine
	rti
	
	ads #$10
	pha, phx, phy, phf ; save registers
	lda #'i', prn      ; print 'i'
	ppf, ppy, ppx, ppa ; load registers
	sbs #$10
jpr }


main_program: ; entry point
	lxy #str_target
	stx $04, sty $05
	lxy #hello_world
	jsr to_upper
	
	lxy #str_target
	jsr print_string
hlt ; finish execution

to_upper:
	{
		lda xy
		cmp #'a'
		jnc {
			cmp #'{'
			jpc {
				sub #$20
			}
		}
		
		if_equal(#'O', brk)
		
		phxy
		ldx $00, ldy $01
		sta xy
		inxy
		stx $00, sty $01
		ppxy
		inxy
		
		tst
	jnz }
rts

.inc "print.asm"

.aln $0100
hello_world: "Hello, World! azAZ`{;\n\0"


.org ram_start ; RAM

.aln $0100, stack_page: byte[stack_size] ; stack
str_target: byte[$0100]

